Design of Algorithms - Homework I (Solutions)
نویسنده
چکیده
Correctness: The first step is to choose a useful loop invariant. Consider the following invariant: At the end of the k iteration of the outer for loop, the array A[1 · · k] is sorted and A[k] is the k smallest element in A. Let us focus on the first execution of the outer for loop. In this case, the inner for loop executes (n− 1) times. After the inner for loop has executed for the first time, A[n − 1] stores the minimum of A[n] and A[n − 1]. After it has executed the second time, A[n − 2] stores the minimum of A[n], A[n − 1] and A[n − 2]. Likewise, when the inner for loop has executed for the (n − 1) time, A[1] stores the minimum of A[n], A[n − 1], . . . , A[1]. It thus follows that at the end of the first iteration, A[1] is the smallest element in A.
منابع مشابه
CS 5314 Randomized Algorithms
Homework 1 (Suggested Solutions) 1. Ans. Use principle of deferred decision. Let X i denote the outcome of the i-th die so that Pr(X i = k) = 1/6, where 1 ≤ k ≤ 6.
متن کاملAERO-THERMODYNAMIC OPTIMIZATION OF TURBOPROP ENGINES USING MULTI-OBJECTIVE GENETIC ALGORITHMS
In this paper multi-objective genetic algorithms were employed for Pareto approach optimization of turboprop engines. The considered objective functions are used to maximize the specific thrust, propulsive efficiency, thermal efficiency, propeller efficiency and minimize the thrust specific fuel consumption. These objectives are usually conflicting with each other. The design variables consist ...
متن کاملar X iv : 1 30 8 . 52 73 v 1 [ cs . S I ] 2 4 A ug 2 01 3 CrowdGrader : Crowdsourcing the Evaluation of Homework Assignments ∗
Crowdsourcing offers a practical method for ranking and scoring large amounts of items. To investigate the algorithms and incentives that can be used in crowdsourcing quality evaluations, we built CrowdGrader, a tool that lets students submit and collaboratively grade solutions to homework assignments. We present the algorithms and techniques used in CrowdGrader, and we describe our results and...
متن کاملCrowdGrader : Crowdsourcing the Evaluation of Homework Assignments ∗ Technical Report UCSC - SOE - 13 - 11 August 2013
Crowdsourcing offers a practical method for ranking and scoring large amounts of items. To investigate the algorithms and incentives that can be used in crowdsourcing quality evaluations, we built CrowdGrader, a tool that lets students submit and collaboratively grade solutions to homework assignments. We present the algorithms and techniques used in CrowdGrader, and we describe our results and...
متن کاملAdvanced Analysis of Algorithms - Homework II (Solutions)
1. Problem 15-2 on Page 364 of [CLRS01]. Solution: Assume that the optimal solution packs the n words in r lines; this solution can be decomposed into two parts, viz., the words packed on the first line and the words packed in the remaining (r − 1) lines. Regardless of the choice for the last word on line 1, the remaining words must be packed optimally in the lines 2 through (r − 1). (Why?) We ...
متن کامل